﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="HexRepresentationItem.cs" company="Voogd en Voogd Diensten">
//   Copyright 2008-2009 Voogd en Voogd Diensten
// </copyright>
// <author>Jelle</author>
// <summary>
//   De HexRepresentationItem class.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace GLCDBaseTypes.BaseTypes
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// Saves the hexadecimal values
    /// </summary>
    public class HexRepresentationItem
    {
        /// <summary>
        /// Leest of schrijft HexValue
        /// </summary>
        public string HexValue { get; set; }

        /// <summary>
        /// Leest of schrijft ToBinary
        /// </summary>
        /// <returns>Retourneert String</returns>
        public string ToBinary()
        {
            string hex = this.HexValue.Trim().Substring(2);

            return Convert.ToString(Convert.ToInt32(hex, 16), 2).PadLeft(8, '0');
        }

        /// <summary>
        /// From binary (formats 0xXX)
        /// </summary>
        /// <param name="binary">De Binary param het type string</param>
        public void FromBinary(string binary)
        {
            this.HexValue = string.Format("0x{0:X1}", Convert.ToInt32(binary, 2));
        }
    }
}
